package cn.com.lyj6851.user.controller;

import java.util.Date;
import java.util.UUID;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.com.lyj6851.common.util.BeanValidator;
import cn.com.lyj6851.user.entity.Menu;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 〈功能简述〉<br>
 * 〈菜单〉
 *
 */
@RestController
@Api(tags = "菜单Controller")
public class MenuController {
	
	@PostMapping("menu")
    @ApiOperation(value = "新增菜单")
	public ResponseEntity<String> addMenu(Menu menu){
		//1.校验
		BeanValidator.check(menu);
		menu.setId(UUID.randomUUID().toString());
        menu.setCreateTime(new Date());
        menu.setEnabled("1");
        menu.insert();
        return ResponseEntity.ok("插入成功!");
	}
	
	@ApiOperation(value = "删除菜单")
    @DeleteMapping("menu")
	public ResponseEntity<String> deleteMenu(Menu menu){
		menu.deleteById();
		return ResponseEntity.ok("删除成功!");
	}
	
	@ApiOperation(value = "修改菜单")
    @PutMapping("menu")
	public ResponseEntity<String> updateMenu(Menu menu){
		//1.校验
		BeanValidator.check(menu);
		menu.updateById();
		return ResponseEntity.ok("修改成功!");
	}
	
	
}
